JObj.JCookie = {};
(function($){
	
	var cks = {};
	var allcookies = document.cookie;
	
	var expires = null; //(new Date()).getTime() + 0 * 24 * 60 * 60 * 1000;
	
	$.setExpires = function(y,m,d,h,i,s,ms){
		var date = new Date(); 
		y = isNaN(y) ? date.getFullYear() : y;
		m = isNaN(m) ? date.getMonth() : m - 1;
		d = isNaN(d) ? date.getDate() : d;
		
		h = isNaN(h) ? date.getHours() : h;
		i = isNaN(i) ? date.getMinutes() : i;
		s = isNaN(s) ? date.getSeconds() : s;
		ms = isNaN(ms) ? date.getMilliseconds() : ms;
		
		expires = new Date(y,m,d,h,i,s,ms).toUTCString();
	}
	
	$.setExpiresByUTCString = function(UTCString){
		var s = new Date(UTCString).toUTCString();
		if(s == 'NaN' || s == 'Invalid Date') return; // IE,Opera NaN , FF,Safari Invalid Date;
		else
			expires = s;
	}
	
		
	if (allcookies != ""){
		
		var cookies = allcookies.split(';');
		
		for(var i=0; i < cookies.length; i++){	// Break each pair into an array
			cookies[i] = cookies[i].split('=');
			cks[(cookies[i][0]).trim()] = decodeURIComponent(cookies[i][1]);
		}
		
		delete cookies;
		delete allcookies;
	}
	

	$.save = function(path, domain, secure){
		for(var prop in cks) {
				var cookie = "";
				cookie = prop + '=' + encodeURIComponent(cks[prop]);
   
				cookie += ";expires=" + expires; 
				if (path) cookie += ";path=" + path;
				if (domain) cookie += ";domain=" + domain;
				if (secure) cookie += ";secure";
				alert(cookie);
				document.cookie = cookie;
			}
	}
	
	$.empty = function(path, domain, secure){
		
		$.save(new Date().getFullYear() - 1, path, domain, secure); 
		/*-----------------------
		Must save(0) first then delete this object's property
		If delete first,save(0) will not save anlything.
		-----------------------*/
		delete cks;
		cks = {};
	}
	
	$.remove = function(k){
		delete cks[k];
	}
	
	$.set = function(k,v){
		cks[k] = v;
	}
	
	$.get = function(k){
		return cks[k];
	}
	
})(JObj.JCookie);